<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible" fullscreen>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
      <el-divider content-position="center">基础信息</el-divider>
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="学生姓名" prop="studentName">
            <el-input v-model="dataForm.studentName" placeholder="学生姓名" size="mini">
              <el-button slot="append" @click="openDialog('person')">查询</el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="性别" prop="gender" disabled>
            <el-select v-model="dataForm.gender" filterable default-first-option placeholder="请选择">
              <el-option label="男" :value="0"></el-option>
              <el-option label="女" :value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="出生日期" prop="birthDay" disabled>
            <el-date-picker v-model="dataForm.birthDay" type="date" placeholder="选择日期时间" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="民族" prop="nationality">
            <el-select v-model="dataForm.nationality">
              <el-option v-for="item in nationalList" :value="item.id" :label="item.name" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="户口类型" prop="accountType">
            <el-select v-model="dataForm.accountType" placeholder="请选择">
              <el-option label="乡村" :value="1"></el-option>
              <el-option label="城市" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="家庭住址" prop="address">
            <el-input v-model="dataForm.address" placeholder="家庭住址" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="center">检查结果</el-divider>
      <el-row class="bg-row">
        <el-col :span="8">
          <el-form-item label="学校">
            <el-input v-model="dataForm.schoolName">
              <el-button slot="append" @click="openDialog('school')">选择</el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="年级">
            <el-input v-model="dataForm.gradeName">
              <el-button slot="append" @click="openDialog('grade')">选择</el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="班级">
            <el-input v-model="dataForm.className">
              <el-button slot="append" @click="openDialog('class')">选择</el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="身高(cm)" prop="height">
            <el-input v-model="dataForm.height" placeholder="身高">
              <template slot="append">CM</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="体重(kg)" prop="weight">
            <el-input v-model="dataForm.weight" placeholder="体重">
              <template slot="append">KG</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="胸围" prop="bust">
            <el-input v-model="dataForm.bust" placeholder="胸围"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="肺活量" prop="vitalCapacity">
            <el-input v-model="dataForm.vitalCapacity" placeholder="肺活量"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="8">
          <el-form-item label="血压左" prop="bloodPressureLeft">
            <el-input v-model="dataForm.bloodPressureLeft" placeholder="血压左"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="血压右" prop="bloodPressureRight">
            <el-input v-model="dataForm.bloodPressureRight" placeholder="血压右"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="脉搏" prop="pulse">
            <el-input v-model="dataForm.pulse" placeholder="脉搏"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="视力左" prop="visionLeft">
            <el-input v-model="dataForm.visionLeft" placeholder="视力左"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="视力右" prop="visionRight">
            <el-input v-model="dataForm.visionRight" placeholder="视力右"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="矫正视力左" prop="correctVisionLeft">
            <el-input v-model="dataForm.correctVisionLeft" placeholder="矫正视力左"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="矫正视力右" prop="correctVisionRight">
            <el-input v-model="dataForm.correctVisionRight" placeholder="矫正视力右"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="眼科左" prop="ophthalmologyLeft">
            <el-select v-model="dataForm.ophthalmologyLeft" filterable default-first-option placeholder="请选择">
              <el-option v-for="item in ophthalmologyList" :value="item.value" :label="item.label" :key="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="眼科右" prop="ophthalmologyRight">
            <el-select v-model="dataForm.ophthalmologyRight" filterable default-first-option placeholder="请选择">
              <el-option v-for="item in ophthalmologyList" :value="item.value" :label="item.label" :key="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="排左" prop="paiLeft">
            <el-input v-model="dataForm.paiLeft" placeholder="排左"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="排右" prop="paiRight">
            <el-input v-model="dataForm.paiRight" placeholder="排右"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="8">
          <el-form-item label="听力左" prop="hearingLeft">
            <el-autocomplete class="inline-input" v-model="dataForm.hearingLeft" :fetch-suggestions="querySearch"
              placeholder="听力左" @select="handleSubmit"></el-autocomplete>
            <!--      <el-input v-model="dataForm.hearingLeft" placeholder="听力左"></el-input>-->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="听力右" prop="hearingRight">
            <el-autocomplete class="inline-input" v-model="dataForm.hearingRight" :fetch-suggestions="querySearch"
              placeholder="听力右" @select="handleSubmit"></el-autocomplete>
            <!--      <el-input v-model="dataForm.hearingRight" placeholder="听力右"></el-input>-->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="沙眼" prop="trachoma">
            <el-autocomplete class="inline-input" v-model="dataForm.trachoma" :fetch-suggestions="querySearch"
              placeholder="沙眼" @select="handleSubmit"></el-autocomplete>
            <!--      <el-input v-model="dataForm.trachoma" placeholder="沙眼"></el-input>-->
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="8">
          <el-form-item label="色觉" prop="colorVision">
            <el-autocomplete class="inline-input" v-model="dataForm.colorVision" :fetch-suggestions="querySearch"
              placeholder="色觉" @select="handleSubmit"></el-autocomplete>
            <!--      <el-input v-model="dataForm.colorVision" placeholder="色觉"></el-input>-->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="鼻病" prop="rhinopathy">
            <el-autocomplete class="inline-input" v-model="dataForm.rhinopathy" :fetch-suggestions="querySearch"
              placeholder="鼻病" @select="handleSubmit"></el-autocomplete>
            <!--      <el-input v-model="dataForm.rhinopathy" placeholder="鼻病"></el-input>-->
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="8">
          <el-form-item label="恒牙龋齿D" prop="permanentTeethCariesD">
            <el-input v-model="dataForm.permanentTeethCariesD" placeholder="恒牙龋齿D"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="恒牙龋齿M" prop="permanentTeethCariesM">
            <el-input v-model="dataForm.permanentTeethCariesM" placeholder="恒牙龋齿M"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="恒牙龋齿F" prop="permanentTeethCariesF">
            <el-input v-model="dataForm.permanentTeethCariesF" placeholder="恒牙龋齿F"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="8">
          <el-form-item label="乳牙龋齿D" prop="deciduousToothDecayD">
            <el-input v-model="dataForm.deciduousToothDecayD" placeholder="乳牙龋齿D"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="乳牙龋齿M" prop="deciduousToothDecayM">
            <el-input v-model="dataForm.deciduousToothDecayM" placeholder="乳牙龋齿M"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="乳牙龋齿F" prop="deciduousToothDecayF">
            <el-input v-model="dataForm.deciduousToothDecayF" placeholder="乳牙龋齿F"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="牙周疾病" prop="priodontalDisease" class="bg-row">
        <el-input v-model="dataForm.priodontalDisease" placeholder="牙周疾病"></el-input>
      </el-form-item>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="心" prop="heart">
            <el-select v-model="dataForm.heart" filterable default-first-option placeholder="请选择">
              <el-option v-for="item in heartList" :value="item.value" :label="item.label" :key="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="肺" prop="lung">
            <el-input v-model="dataForm.lung" placeholder="肺"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="肝" prop="liver">
            <el-input v-model="dataForm.liver" placeholder="肝"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="脾" prop="spleen">
            <el-input v-model="dataForm.spleen" placeholder="脾"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="脊柱" prop="spine">
            <el-input v-model="dataForm.spine" placeholder="脊柱"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="平足" prop="flatFeet">
            <el-input v-model="dataForm.flatFeet" placeholder="平足"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="四肢" prop="limbs">
            <el-input v-model="dataForm.limbs" placeholder="四肢"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="皮肤" prop="skin">
            <el-input v-model="dataForm.skin" placeholder="皮肤"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="传染病" prop="infectiousDisease">
            <el-input v-model="dataForm.infectiousDisease" placeholder="传染病"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="胸透" prop="chestXRay">
            <el-input v-model="dataForm.chestXRay" placeholder="胸透"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="粪检" prop="fecalExamination">
            <el-select v-model="dataForm.fecalExamination" filterable default-first-option placeholder="请选择">
              <el-option v-for="item in fecalList" :value="item.value" :label="item.label" :key="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="血红蛋白" prop="hemoglobin">
            <el-input v-model="dataForm.hemoglobin" placeholder="血红蛋白"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="肝炎" prop="hepatitis">
            <el-input v-model="dataForm.hepatitis" placeholder="肝炎"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="肺结核" prop="tuberculosis">
            <el-input v-model="dataForm.tuberculosis" placeholder="肺结核"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="先天性心脏病" prop="congenitalHeartDisease">
            <el-input v-model="dataForm.congenitalHeartDisease" placeholder="先天性心脏病"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="肾炎" prop="nephritis">
            <el-input v-model="dataForm.nephritis" placeholder="肾炎"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="6">
          <el-form-item label="风湿病" prop="rheumatism">
            <el-input v-model="dataForm.rheumatism" placeholder="风湿病"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="谷丙转氨酶" prop="alanineAminotransferase">
            <el-input v-model="dataForm.alanineAminotransferase" placeholder="谷丙转氨酶"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="总胆红素" prop="totalBilirubin">
            <el-input v-model="dataForm.totalBilirubin" placeholder="总胆红素"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="其他病症" prop="otherInformation">
            <el-input v-model="dataForm.otherInformation" placeholder="其他病症"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="24">
          <el-form-item label="其他病症" prop="otherInformation">
            <el-input v-model="dataForm.otherInformation" placeholder="其他病症"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="24">
          <el-form-item label="发育评价" prop="heightEvaluation">
            <el-autocomplete class="inline-input" v-model="dataForm.heightEvaluation" :fetch-suggestions="querySearch1"
              placeholder="身高评价" @select="handleSubmit"></el-autocomplete>
            <!--      <el-input v-model="dataForm.heightEvaluation" placeholder="身高评价"></el-input>-->
          </el-form-item>
        </el-col>
      </el-row>

      <!--    <el-form-item label="体重评价" prop="weightEvaluation">-->
      <!--      <el-input v-model="dataForm.weightEvaluation" placeholder="体重评价"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="营养评价" prop="nutritionalEvaluation">-->
      <!--      <el-input v-model="dataForm.nutritionalEvaluation" placeholder="营养评价"></el-input>-->
      <!--    </el-form-item>-->
      <el-form-item label="视力评价" prop="visionEvaluation" class="bg-row">
        <el-input v-model="dataForm.visionEvaluation" placeholder="视力评价"></el-input>
      </el-form-item>
      <!--    <el-form-item label="创建时间" prop="createTime">-->
      <!--      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="更新时间" prop="updateTime">-->
      <!--      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="创建用户id" prop="createUser">-->
      <!--      <el-input v-model="dataForm.createUser" placeholder="创建用户id"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="修改用户id" prop="updateUser">-->
      <!--      <el-input v-model="dataForm.updateUser" placeholder="修改用户id"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="单位id" prop="unitId">-->
      <!--      <el-input v-model="dataForm.unitId" placeholder="单位id"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="租户id" prop="tenantId">-->
      <!--      <el-input v-model="dataForm.tenantId" placeholder="租户id"></el-input>-->
      <!--    </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    <!-- 弹窗，选择学校 -->
    <search-school v-if="schoolVisible" ref="schoolDialog" @refreshForm="getSchoolData"></search-school>
    <!-- 弹窗，选择年级 -->
    <search-grade v-if="gradeVisible" ref="gradeDialog" @refreshForm="getGradeData"></search-grade>
    <!-- 弹窗，选择班级 -->
    <search-class v-if="classVisible" ref="classDialog" @refreshForm="getClassData"></search-class>
    <!-- 弹窗，选择人员 -->
    <search-person v-if="personVisible" ref="personDialog" @refreshForm="getPersonData"></search-person>
  </el-dialog>
</template>

<script>
  import {
    getPvmMedicalReportObj,
    addPvmMedicalReportObj,
    putPvmMedicalReportObj,
    getChildrenEvaluate
  } from '@/api/pvm/pvmmedicalreport'
  import { fetchNationalList } from '@/api/admin/national'
  import { getObj } from "@/api/pvm/student"
  import { getClassOptions, getSchoolObj } from "@/api/pvm/school"
  import { getGradeBySchoolId } from "@/api/pvm/grade"
  import { remote } from "@/api/admin/dict"
  import { getPersonObj } from "@/api/pvm/person"

  import SearchSchool from '@/views/pvm/teacher/components/SearchSchool'
  import SearchGrade from '@/views/pvm/class/components/SearchGrade'
  import SearchClass from '@/views/pvm/checkdata/SearchClass'
  import SearchPerson from '@/components/business/person-search'

  export default {
    data() {
      // 自定义检查基本信息是否填写
      var validateMsg = (rule, value, callback) => {
        if (!this.dataForm.height && !this.dataForm.width && !this.dataForm.birthDay && !this.dataForm.gender) {
          callback(new Error('请输入基本信息'));
        } else {
          callback();
        }
      };
      // 身高限制
      var heightRule = (rule, value, callback) => {
        if (this.dataForm.height < 45 || this.dataForm.height > 210) {
          callback(new Error('请检查输入的身高是否合理'));
        } else {
          callback();
        }
      };
      // 体重限制
      var weightRule = (rule, value, callback) => {
        if (this.dataForm.weight < 1.9 || this.dataForm.weight > 200) {
          callback(new Error('请检查输入的体重是否合理'));
        } else {
          callback();
        }
      };
      return {
        visible: false,
        heartList: [],
        fecalList: [],
        ophthalmologyList: [],
        dataForm: {
          id: 0,
          studentName: '',
          birthDay: '',
          gender: '',
          nationality: '',
          accountType: '',
          address: '',
          height: '',
          weight: '',
          bust: '',
          vitalCapacity: '',
          bloodPressureLeft: '',
          bloodPressureRight: '',
          pulse: '',
          visionLeft: '',
          visionRight: '',
          correctVisionLeft: '',
          correctVisionRight: '',
          paiLeft: '',
          paiRight: '',
          hearingLeft: '正常',
          hearingRight: '正常',
          trachoma: '正常',
          colorVision: '正常',
          rhinopathy: '正常',
          permanentTeethCariesD: '',
          permanentTeethCariesM: '',
          permanentTeethCariesF: '',
          deciduousToothDecayD: '',
          deciduousToothDecayM: '',
          deciduousToothDecayF: '',
          priodontalDisease: '',
          heart: '(-)',
          lung: '(-)',
          liver: '未触及',
          spleen: '未触及',
          spine: '正常',
          flatFeet: '正常',
          limbs: '正常',
          skin: '正常',
          infectiousDisease: '',
          chestXRay: '',
          fecalExamination: '',
          hemoglobin: '',
          hepatitis: '无',
          tuberculosis: '无',
          congenitalHeartDisease: '无',
          nephritis: '无',
          rheumatism: '无',
          alanineAminotransferase: '',
          totalBilirubin: '',
          otherInformation: '',
          heightEvaluation: '',
          weightEvaluation: '',
          nutritionalEvaluation: '',
          visionEvaluation: '',
          // createTime: '',
          // updateTime: '',
          // createUser: '',
          // updateUser: '',
          // unitId: '',
          // tenantId: ''
        },
        dataRule: {
          studentName: [{required: true,message: '学生姓名不能为空',trigger: 'blur'}],
          birthDay: [{required: true,message: '出生年月不能为空',trigger: 'blur'}],
          gender: [{
            required: true,
            message: '性别不能为空',
            trigger: 'blur'
          }],
          nationality: [{
            required: false,
            message: '民族不能为空',
            trigger: 'blur'
          }],
          accountType: [{
            required: false,
            message: '户口类型不能为空',
            trigger: 'blur'
          }],
          address: [{
            required: false,
            message: '家庭住址不能为空',
            trigger: 'blur'
          }],
          height: [{
              required: true,
              message: '身高不能为空',
              trigger: 'blur'
            },
            {
              validator: heightRule,
              trigger: 'blur'
            }
          ],
          weight: [{
              required: true,
              message: '体重不能为空',
              trigger: 'blur'
            },
            {
              validator: weightRule,
              trigger: 'blur'
            }
          ],
          bust: [{
            required: false,
            message: '胸围不能为空',
            trigger: 'blur'
          }],
          vitalCapacity: [{
            required: false,
            message: '肺活量不能为空',
            trigger: 'blur'
          }],
          bloodPressureLeft: [{
            required: false,
            message: '血压左不能为空',
            trigger: 'blur'
          }],
          bloodPressureRight: [{
            required: false,
            message: '血压右不能为空',
            trigger: 'blur'
          }],
          pulse: [{
            required: true,
            message: '脉搏不能为空',
            trigger: 'blur'
          }],
          visionLeft: [{
            required: true,
            message: '视力左不能为空',
            trigger: 'blur'
          }],
          visionRight: [{
            required: true,
            message: '视力右不能为空',
            trigger: 'blur'
          }],
          correctVisionLeft: [{
            required: false,
            message: '矫正视力左不能为空',
            trigger: 'blur'
          }],
          correctVisionRight: [{
            required: false,
            message: '矫正视力右不能为空',
            trigger: 'blur'
          }],
          paiLeft: [{
            required: false,
            message: '排左不能为空',
            trigger: 'blur'
          }],
          paiRight: [{
            required: false,
            message: '排右不能为空',
            trigger: 'blur'
          }],
          hearingLeft: [{
            required: true,
            message: '听力左不能为空',
            trigger: 'change'
          }],
          hearingRight: [{
            required: true,
            message: '听力右不能为空',
            trigger: 'change'
          }],
          trachoma: [{
            required: true,
            message: '沙眼不能为空',
            trigger: 'change'
          }],
          colorVision: [{
            required: true,
            message: '色觉不能为空',
            trigger: 'change'
          }],
          rhinopathy: [{
            required: true,
            message: '鼻病不能为空',
            trigger: 'change'
          }],
          permanentTeethCariesD: [{
            required: false,
            message: '恒牙龋齿D不能为空',
            trigger: 'blur'
          }],
          permanentTeethCariesM: [{
            required: false,
            message: '恒牙龋齿M不能为空',
            trigger: 'blur'
          }],
          permanentTeethCariesF: [{
            required: false,
            message: '恒牙龋齿F不能为空',
            trigger: 'blur'
          }],
          deciduousToothDecayD: [{
            required: false,
            message: '乳牙龋齿D不能为空',
            trigger: 'blur'
          }],
          deciduousToothDecayM: [{
            required: false,
            message: '乳牙龋齿M不能为空',
            trigger: 'blur'
          }],
          deciduousToothDecayF: [{
            required: false,
            message: '乳牙龋齿F不能为空',
            trigger: 'blur'
          }],
          priodontalDisease: [{
            required: false,
            message: '牙周疾病不能为空',
            trigger: 'blur'
          }],
          heart: [{
            required: true,
            message: '心不能为空',
            trigger: 'blur'
          }],
          lung: [{
            required: true,
            message: '肺不能为空',
            trigger: 'blur'
          }],
          liver: [{
            required: true,
            message: '肝不能为空',
            trigger: 'blur'
          }],
          spleen: [{
            required: true,
            message: '脾不能为空',
            trigger: 'blur'
          }],
          spine: [{
            required: true,
            message: '脊柱不能为空',
            trigger: 'blur'
          }],
          flatFeet: [{
            required: true,
            message: '平足不能为空',
            trigger: 'blur'
          }],
          limbs: [{
            required: true,
            message: '四肢不能为空',
            trigger: 'blur'
          }],
          skin: [{
            required: true,
            message: '皮肤不能为空',
            trigger: 'blur'
          }],
          infectiousDisease: [{
            required: false,
            message: '传染病不能为空',
            trigger: 'blur'
          }],
          chestXRay: [{
            required: false,
            message: '胸透不能为空',
            trigger: 'blur'
          }],
          fecalExamination: [{
            required: false,
            message: '粪检不能为空',
            trigger: 'blur'
          }],
          hemoglobin: [{
            required: true,
            message: '血红蛋白不能为空',
            trigger: 'blur'
          }],
          hepatitis: [{
            required: true,
            message: '肝炎不能为空',
            trigger: 'blur'
          }],
          tuberculosis: [{
            required: true,
            message: '肺结核不能为空',
            trigger: 'blur'
          }],
          congenitalHeartDisease: [{
            required: true,
            message: '先天性心脏病不能为空',
            trigger: 'blur'
          }],
          nephritis: [{
            required: true,
            message: '肾炎不能为空',
            trigger: 'blur'
          }],
          rheumatism: [{
            required: true,
            message: '风湿病不能为空',
            trigger: 'blur'
          }],
          alanineAminotransferase: [{
            required: true,
            message: '谷丙转氨酶不能为空',
            trigger: 'blur'
          }],
          totalBilirubin: [{
            required: true,
            message: '总胆红素不能为空',
            trigger: 'blur'
          }],
          otherInformation: [{
            required: false,
            message: '其他病症不能为空',
            trigger: 'blur'
          }],
          heightEvaluation: [{
            validator: validateMsg,
            trigger: 'blur'
          }],
          weightEvaluation: [{
            required: true,
            message: '体重评价不能为空',
            trigger: 'blur'
          }],
          nutritionalEvaluation: [{
            required: true,
            message: '营养评价不能为空',
            trigger: 'blur'
          }],
          visionEvaluation: [{
            required: true,
            message: '视力评价不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
          updateTime: [{
            required: true,
            message: '更新时间不能为空',
            trigger: 'blur'
          }],
          createUser: [{
            required: true,
            message: '创建用户id不能为空',
            trigger: 'blur'
          }],
          updateUser: [{
            required: true,
            message: '修改用户id不能为空',
            trigger: 'blur'
          }],
          unitId: [{
            required: true,
            message: '单位id不能为空',
            trigger: 'blur'
          }],
          tenantId: [{
            required: true,
            message: '租户id不能为空',
            trigger: 'blur'
          }]
        },
        nationalList: [],
        schoolVisible: false,
        gradeVisible: false,
        classVisible: false,
        personVisible: false,
      }
    },
    components: {
      SearchSchool,
      SearchGrade,
      SearchClass,
      SearchPerson
    },
    methods: {
      // 获取民族列表
      getNationalList() {
        fetchNationalList({
          current: 1,
          size: 100
        }).then(response => {
          if(response.data.code == '0'){
            this.nationalList = response.data.data.records
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      openDialog(type) {
        if (type == 'school') {
          let form = {
            province: this.dataForm.pvmCheckdata.province,
            city: this.dataForm.pvmCheckdata.city,
            area: this.dataForm.pvmCheckdata.area,
            schoolType: this.dataForm.pvmCheckdata.schoolType
          }
          this.schoolVisible = true
          this.$nextTick(() => {
            this.$refs.schoolDialog.init(JSON.stringify(form))
          })
        } else if (type == 'grade') {
          if (this.dataForm.pvmCheckdata.schoolId) {
            let form = {
              schoolType: this.dataForm.pvmCheckdata.schoolType
            }
            this.gradeVisible = true
            this.$nextTick(() => {
              this.$refs.gradeDialog.init(JSON.stringify(form))
            })
          } else {
            this.$message.warning('请先选择学校')
          }
        } else if (type == 'class') {
          if (this.dataForm.pvmCheckdata.gradeId) {
            let form = {
              schoolId: this.dataForm.pvmCheckdata.schoolId,
              schoolName: this.dataForm.pvmCheckdata.schoolName,
              gradeId: this.dataForm.pvmCheckdata.gradeId,
              gradeName: this.dataForm.pvmCheckdata.gradeName
            }
            this.classVisible = true
            this.$nextTick(() => {
              this.$refs.classDialog.init(JSON.stringify(form))
            })
          } else {
            this.$message.warning('请先选择学校年级')
          }
        } else if (type == 'person') {
          this.personVisible = true
          this.$nextTick(() => {
            this.$refs.personDialog.init()
          })
        }

      },
      init(id) {
        //this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          remote('heart_type').then(response => {
            this.heartList = response.data.data
          })
          remote('fecal_examination').then(response => {
            this.fecalList = response.data.data
          })
          remote('ophthalmology_list').then(response => {
            this.ophthalmologyList = response.data.data
          })

          this.getNationalList()
          this.$refs['dataForm'].resetFields()
          if (id) {
            getObj(id).then(res => {
              if(res.data.code == '0'){
                this.studentData = res.data.data
                this.dataForm.studentId = this.studentData.id
                this.dataForm.schoolName = this.studentData.schoolName
                this.dataForm.gradeName = this.studentData.gradeName
                this.dataForm.className = this.studentData.className
                getSchoolObj(this.studentData.schoolId).then(response => {
                  if(response.data.code == '0'){
                    this.$set(this.studentData, 'schoolName', response.data.data.schoolName)
                    this.$set(this.studentData, 'schoolCode', response.data.data.schoolCode)
                  }else{
                    this.$message.error(response.data.msg)
                  }
                })
                getGradeBySchoolId(this.studentData.schoolId).then(response => {
                  if(response.data.code == '0'){
                    this.gradeOptions = response.data.data
                  }else{
                    this.$message.error(response.data.msg)
                  }
                })
                getClassOptions(this.studentData.schoolId,this.studentData.gradeId).then(response => {
                  if(response.data.code == '0'){
                    this.classOptions = response.data.data
                  }else{
                    this.$message.error(response.data.msg)
                  }
                })
                this.dataForm.studentName = this.studentData.studentName;
                this.dataForm.gender = this.studentData.gender;
                this.dataForm.birthDay = this.studentData.birthDay;
                //this.dataForm.studentId = this.studentData.id;
                getPvmMedicalReportObj(this.dataForm.studentId).then(response => {
                  if(response.data.code == '0'){
                    if (response.data.data.accountType != "-1") {
                      this.dataForm = response.data.data
                      this.$set(this.dataForm, 'nationality', Number(this.dataForm.nationality))
                      this.$set(this.dataForm, 'accountType', Number(this.dataForm.accountType))
                    }
                  }else{
                    this.$message.error(response.data.msg)
                  }
                })
              }else{
                this.$message.error(res.data.msg)
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
              putPvmMedicalReportObj(this.dataForm).then(response => {
                if(response.data.code == '0'){
                  this.$message.success('修改成功')
                  this.visible = false
                  this.$emit('refreshDataList')
                }else{
                  this.$message.error(response.data.msg)
                }
              })
            } else {
              addPvmMedicalReportObj(this.dataForm).then(response => {
                if(response.data.code == '0'){
                  this.$message.success('添加成功')
                  this.visible = false
                  this.$emit('refreshDataList')
                }else{
                  this.$message.error(response.data.msg)
                }
              })
            }
          }
        })
      },
      getSchoolData(val) {
        this.$set(this.dataForm.pvmCheckdata, 'schoolId', val.id)
        this.$set(this.dataForm, 'schoolName', val.schoolName)
        this.$set(this.dataForm.pvmCheckdata, 'schoolName', val.schoolName)
        this.$set(this.dataForm.pvmCheckdata, 'schoolType', val.schoolType)
      },
      getGradeData(val) {
        this.$set(this.dataForm.pvmCheckdata, 'gradeId', val.id)
        this.$set(this.dataForm.pvmCheckdata, 'gradeName', val.gradeName)
        this.$set(this.dataForm, 'gradeName', val.gradeName)
      },
      getClassData(val) {
        this.$set(this.dataForm.pvmCheckdata, 'classId', val.id)
        this.$set(this.dataForm.pvmCheckdata, 'className', val.className)
        this.$set(this.dataForm, 'className', val.className)
      },
      getPersonData(val) {
        getPersonObj(val.id).then(response => {
          if(response.data.code == '0'){
            let responseData = response.data.data
            if (responseData) {
              this.dataForm.birthDay = responseData.birthDay
              this.dataForm.gender = responseData.gender
              this.dataForm.studentName = responseData.name
              this.dataForm.address = responseData.address
            }
            this.personInfo = response.data.data
            this.dataForm.pvmCheckdata = {}
            if (responseData.pvmStudent) {
              this.dataForm.pvmCheckdata.schoolId = responseData.pvmStudent.schoolId
              this.dataForm.pvmCheckdata.schoolName = responseData.pvmStudent.schoolName
              this.dataForm.pvmCheckdata.schoolType = responseData.pvmStudent.schoolType
              this.dataForm.pvmCheckdata.gradeId = responseData.pvmStudent.gradeId
              this.dataForm.pvmCheckdata.gradeName = responseData.pvmStudent.gradeName
              this.dataForm.pvmCheckdata.classId = responseData.pvmStudent.classId
              this.dataForm.pvmCheckdata.className = responseData.pvmStudent.className
            }
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      handleSubmit() {
        //根据自身情况
        //该方法是提交时触发
      },
      //输入框获取焦点时调用的方法
      querySearch(queryString, cb) {
        //allInfos是怎么来，是从父组件传过来的还是在自己组件调用api接口拿到的还是其他
        //我这里的allInfos是从父组件传过来的，在这里也举例子组件从父组件传值
        let results = [{
          "value": "正常"
        }];
        // results = queryString
        //   ? results.filter(this.createFilter(queryString))
        //   : results;
        //cb是回调函数，返回筛选出的结果数据到输入框下面的输入列表
        cb(results);
      },
      // 判断儿童生长发育情况变成选项
      querySearch1(queryString, cb) {
        if (!this.dataForm.height && !this.dataForm.width && !this.dataForm.birthDay && !this.dataForm.gender) {
          cb();
        } else {
          let results = [];
          getChildrenEvaluate(this.dataForm).then(response => {
            if(response.data.code == '0'){
              results = data.data.data
            }else{
              this.$message.error(response.data.msg)
            }
          })
          let timeout;
          clearTimeout(timeout);
          timeout = setTimeout(() => {
            cb(results);
          }, 1000);
        }
      },
    }
  }
</script>
<style lang="scss" scoped>
  .bg-row {
    // background-color: #cadee8;
    padding-left: 15px;
    padding-top: 5px;
  }

  .miui-table {
    width: 100%;
    margin: 10px 0;
    background-color: #b1e2ec3b;

    tr th {
      background-color: #f4f5f7;
    }

    tr th,
    tr td {
      padding: 10px 8px;
      border: solid 1px #e7e7e7;
      text-align: left;
    }

    .miui-table-header td {
      background-color: #7898a8;
      color: #fff;
      text-align: center;
    }

    .miui-table-tbody {
      background-color: #cadee8;
    }
  }
</style>
